#include "playobject.h"

PlayObject::PlayObject(QWidget *parent)
    : QWidget{parent}
{
    _img.load("D:/Desktop/test.png");
    update();

    _demux = new Demux(this);
    connect(_demux, &Demux::sendQImage, this, &PlayObject::receiveQImage);
}

void PlayObject::setUrl(const QString &url)
{
    _demux->setUrl(url);
}

void PlayObject::paly()
{
    _demux->paly();
}

void PlayObject::stop()
{
    _demux->stop();
}

void PlayObject::setPause()
{
    _demux->setPause();
}

void PlayObject::setSpeed(const double &speed)
{
    _demux->setSpeed(speed);
}

void PlayObject::setPreviousFrame()
{
    _demux->setPreviousFrame();
}

void PlayObject::seekFrame(const bool &isNextFrame)
{
    _demux->seekFrame(isNextFrame);
}

Demux *PlayObject::getDemux()
{
    return _demux;
}

void PlayObject::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.drawImage(0,0,_img.scaled(this->size()));
}

void PlayObject::receiveQImage(const QImage &img)
{
    _img = img.scaled(this->size());
    update();
}
